package com.example.newbiechen.ireader.ui.adapter;

import android.support.v7.widget.RecyclerView;

import com.example.newbiechen.ireader.model.bean.CollBookBean;
import com.example.newbiechen.ireader.ui.adapter.view.CollBookHolder;
import com.example.newbiechen.ireader.ui.adapter.view.HorizonTagHolder;
import com.example.newbiechen.ireader.ui.base.adapter.BaseListAdapter;
import com.example.newbiechen.ireader.ui.base.adapter.BaseViewHolder;
import com.example.newbiechen.ireader.ui.base.adapter.IViewHolder;
import com.example.newbiechen.ireader.widget.adapter.WholeAdapter;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by newbiechen on 17-5-8.
 */

public class CollBookAdapter extends WholeAdapter<CollBookBean> {
    private Map<Integer, CollBookBean> map = new HashMap<Integer, CollBookBean>();
    private OnItemClick mCallback;
    public interface OnItemClick{
        void delete(Map<Integer, CollBookBean> map);
    }
    @Override
    protected IViewHolder<CollBookBean> createViewHolder(int viewType) {
        CollBookHolder collBookHolder = new CollBookHolder();
        collBookHolder.setOnItemClick(new CollBookHolder.OnItemClick() {
            @Override
            public void delete(int position, boolean checked) {
                getItem(position).setSelect(checked);
                if (getItem(position).isSelect()) {
                    map.put(position, getItem(position));
                }else {
                    map.remove(position);
                }
                if (mCallback != null){
                    mCallback.delete(map);
                }
            }
        });
        return collBookHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        super.onBindViewHolder(holder, position);

//        //配置点击事件改变状态
//        IViewHolder iHolder = ((BaseViewHolder) holder).holder;
//        CollBookHolder collBookHolder = (CollBookHolder) iHolder;

    }
    public void setOnItemClick(OnItemClick callback){
        mCallback = callback;
    }
}
